/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package solitairetest;

import java.awt.*;
import java.awt.image.*;
import java.util.Vector;

import solitairetest.logic.*;

/**
 *
 * @author Administrator
 */
public class KlondikeDrawPile extends Pile
{
    //public Deck pile;
    private KlondikeDonePile donePile;

    public KlondikeDrawPile(KlondikeDonePile donePile, BufferedImage cards)
    {
        super();

        this.cards = cards;
        this.donePile = donePile;

        Deck deck = new Deck();
        deck.FillPile(false);
        deck.Shuffle();

        for (int i = 0; i < deck.Size(); i++)
        {
            CardCanvas cc = new CardCanvas(deck.GetCard(i), cards);
            this.add(cc);
        }
    }

    public KlondikeDrawPile(KlondikeDonePile donePile, Deck deck, BufferedImage cards)
    {
        super();

        this.cards = cards;
        this.donePile = donePile;

        for (int i = 0; i < deck.Size(); i++)
        {
            CardCanvas cc = new CardCanvas(deck.GetCard(i), cards);
            this.add(cc);
        }
    }

    public java.awt.Component add(CardCanvas cc)
    {
        cc.pile = this;
        this.pileCards.add(cc);

        this.Redraw();

        return cc;
    }

    public void Redraw()
    {
        this.removeAll();

        for (int i = this.pileCards.size() - 1; i >= 0; i--)
        {
            double x = Math.floor(i / 6) * 4;
            this.pileCards.elementAt(i).setLocation(1 + (int)x, 1);
            this.add((Component)this.pileCards.elementAt(i));
        }
    }

    public void CardClicked(boolean isTopMost)
    {
        if (isTopMost)
        {
            this.donePile.add(this.pileCards.lastElement());
            this.pileCards.remove(this.pileCards.lastElement());
            this.Redraw();
        }
    }

    public void paint(Graphics g)
    {
        g.setColor(Color.gray);
        g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
    }
}
